home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Apple Script / OSAX / Mount Volume / MountVolOSAX.c < prev    next >
Text File  |  1993-11-01  |  4KB  |  197 lines

  1. #define SystemSevenOrLater 1
  2. /*
  3.  
  4. c mountvolosax.c -b -b2 -b3 -sym full
  5. link    -t osax -c ascr -rt osax=0 -m MOUNTAFPVOLUME ∂
  6.         -sg "AEVTaevtmntv" -ra "AEVTaevtmntv"=resSysHeap,resLocked ∂
  7.         MountVolOSAX.c.o "{Libraries}Interface.o" "{CLibraries}StdCLib.o" ∂
  8.         -o MountVol -sym full
  9.         
  10. */
  11.  
  12. #ifndef __STRING__
  13. #include <String.h>
  14. #endif
  15.  
  16. #ifndef __MEMORY__
  17. #include <Memory.h>
  18. #endif
  19.  
  20. #ifndef __FILES__
  21. #include <Files.h>
  22. #endif 
  23.  
  24. #ifndef __STRINGS__
  25. #include <Strings.h>
  26. #endif
  27.  
  28. #ifndef __ERRORS__
  29. #include <Errors.h>
  30. #endif
  31.  
  32. #ifndef __APPLEEVENTS__
  33. #include <AppleEvents.h>
  34. #endif
  35. enum
  36. {
  37.     // flag values
  38.  
  39.     kNormalMountFlags = 0, kInhibitMsgFlags
  40. };
  41.  
  42.  
  43. typedef unsigned char Str8[9];
  44.  
  45. typedef struct
  46. {
  47.     short length;
  48.     VolumeType media;
  49.     short flags;
  50.     SignedByte nbpInterval;
  51.     SignedByte nbpCount;
  52.     short uamType;
  53.     short zoneNameOffset;
  54.     short serverNameOffset;
  55.     short volNameOffset;
  56.     short userNameOffset;
  57.     short userPasswordOffset;
  58.     short volPasswordOffset;
  59.     Str31 zoneName;
  60.     Str31 serverName;
  61.     Str27 volName;
  62.     Str31 userName;
  63.     Str8 userPassword;
  64.     Str8 volPassword;
  65. } AFPVolMountInfoRec;
  66.  
  67. typedef AFPVolMountInfoRec* AFPVolMountPtr;
  68.  
  69. void SetErrorValue(AEDesc* result, short error);
  70. OSErr VolumeMount(AFPVolMountPtr pc);
  71. OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString);
  72.  
  73. pascal OSErr MountAFPVolume(AppleEvent *in, AppleEvent *out, long)
  74. {
  75.     OSErr            error;
  76.     short            uamType = kNoUserAuthentication;
  77.     AFPVolMountPtr    pb;
  78.     
  79.     pb = (AFPVolMountPtr) NewPtrClear(sizeof(AFPVolMountInfoRec));
  80.     if (!pb)
  81.     {
  82.         error = MemError();
  83.         goto exit;
  84.     }
  85.     
  86.     error = Get1Parameter(in, 'ZONE', 31, pb->zoneName);
  87.     if (error) goto exit;
  88.     
  89.     error = Get1Parameter(in, 'SRVR', 31, pb->serverName);
  90.     if (error) goto exit;
  91.     
  92.     error = Get1Parameter(in, 'VOLM', 27, pb->volName);
  93.     if (error) goto exit;
  94.     
  95.     error = Get1Parameter(in, 'USER', 31, pb->userName);
  96.     if (!error)
  97.     {
  98.         error = Get1Parameter(in, 'PASS', 8, pb->userPassword);
  99.         uamType = kPassword;
  100.     }
  101.     
  102.     pb->length = sizeof(AFPVolMountInfoRec);
  103.     pb->media = AppleShareMediaType;
  104.     pb->flags = kNormalMountFlags;
  105.     pb->nbpInterval = 2;
  106.     pb->nbpCount = 2;
  107.     pb->uamType = uamType;
  108.     pb->zoneNameOffset = 24;
  109.     pb->serverNameOffset = 56;
  110.     pb->volNameOffset = 88;
  111.     pb->userNameOffset = 116;
  112.     pb->userPasswordOffset = 148;
  113.     pb->volPasswordOffset = 157;
  114.     error = VolumeMount(pb);
  115.     SetErrorValue(out, error);
  116.     error = noErr;
  117. exit:
  118.     return error;
  119. }
  120.  
  121. OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString)
  122. {
  123.     DescType        theType;
  124.     OSErr            error;
  125.     Size            paramSize;
  126.  
  127.     error = AESizeOfParam(in, type, &theType, ¶mSize);
  128.     if (error) goto exit;
  129.     
  130.     error = AEGetParamPtr(in, type, typeChar, &theType, (Ptr) theString, size, ¶mSize);
  131.     if (error) goto exit;
  132.  
  133.     c2pstr((char *)theString);
  134.  
  135. exit:
  136.     return error;
  137. }
  138.  
  139. OSErr VolumeMount(AFPVolMountPtr pc)
  140. {
  141.     OSErr error;
  142.  
  143.     IOParam pb;
  144.     pb.ioBuffer = (Ptr)pc;
  145.     error = PBVolumeMount((ParmBlkPtr) & pb);
  146.     return error;
  147. }
  148.  
  149. void SetErrorValue(AppleEvent* result, short error)
  150. {
  151.     Str255 theError;
  152.     short    length;
  153.  
  154.     switch (error)
  155.     {
  156.         case noErr:
  157.             strcpy(theError, "0");
  158.             break;
  159.         case notOpenErr:
  160.             strcpy(theError, "AppleTalk not open. Please turn on AppleTalk™ in the Chooser");
  161.             break;
  162.         case nsvErr:
  163.             strcpy(theError, "The volume does not exist.");
  164.             break;
  165.         case paramErr:
  166.             strcpy(theError, "Parameter Error!");
  167.             break;
  168.         case extFSErr:
  169.             strcpy(theError, "Appleshare is not installed! Please move AppleShare into the Extensions folder.");
  170.             break;
  171.         case afpNoServer:
  172.             strcpy(theError, "The specified server doesn’t exist.");
  173.             break;
  174.         case afpUserNotAuth:
  175.             strcpy(theError, "Unable to authenticate user.");
  176.             break;
  177.         case afpPwdExpiredErr:
  178.             strcpy(theError, "The password has expired.");
  179.             break;
  180.         case afpAccessDenied:
  181.             strcpy(theError, "Access denied. Update the password.");
  182.             break;
  183.         case aspNoMoreSess:
  184.         case aspServerBusy:
  185.         case aspTooMany:
  186.             strcpy(theError, "There are too many users logged into the server. Please try again later.");
  187.             break;
  188.         default:
  189.             strcpy(theError, "A network error occurred! Please make sure that EtherTalk is selected in the Network Control Panel.");
  190.             break;
  191.     }
  192.     length = strlen(theError);
  193.     AEPutParamPtr(result, keyDirectObject,typeChar,(Ptr) theError, length);
  194. }
  195.  
  196.  
  197.